#include <it/io.h>
#include <it/mat.h>
#include <stdio.h>

/*

TP RAR-R

receiver file

*/

void plot_wav( const char * filename, ivec v ) {
  int i;
  FILE * F = fopen( filename, "w+b" );
  for( i = 0 ; i < ivec_length( v ) ; i++ )
    fprintf( F, "%d %d\n", i, v[ i ] );
  fclose( F );
}


int main()
{
  const char * filename_in  = "signal.wav";
  const char * filename_plot = "signal.plot";

  /* wav file parameters */
  int depth;
  int srate;   
  int nb_channels;
  int nb_samples;
  int freq = 440;
  
  imat m;
  ivec v;

  /* Read wav header */
  if(!wav_info( filename_in, &nb_channels, &srate, &depth, &nb_samples )) {
    fprintf(stderr, "unable to open file %s\n", filename_in );
    return(1);
  }

  printf( "file name = %s\nchannels = %d\nsampling rate = %d\ndepth = %d\nnb_samples = %d samples\n",
	  filename_in, nb_channels, srate, depth, nb_samples );

  /* Read wav content */
  m = imat_wav_read(filename_in);
  v = m[ 0 ];

  plot_wav(filename_plot, v );

  imat_delete(m);
  return 0;
}
